package com.spring.dao;

import com.spring.domain.ProductBean;
import org.apache.ibatis.jdbc.SQL;

public class ProductBeanSqlProvider {

    public String insertSelective(ProductBean record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("product");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getProductName() != null) {
            sql.VALUES("product_name", "#{productName,jdbcType=VARCHAR}");
        }
        
        if (record.getPrice() != null) {
            sql.VALUES("price", "#{price,jdbcType=INTEGER}");
        }
        
        if (record.getProductDesc() != null) {
            sql.VALUES("product_desc", "#{productDesc,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(ProductBean record) {
        SQL sql = new SQL();
        sql.UPDATE("product");
        
        if (record.getProductName() != null) {
            sql.SET("product_name = #{productName,jdbcType=VARCHAR}");
        }
        
        if (record.getPrice() != null) {
            sql.SET("price = #{price,jdbcType=INTEGER}");
        }
        
        if (record.getProductDesc() != null) {
            sql.SET("product_desc = #{productDesc,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}